package com.celtic.dao.impl;

import java.util.List;

import org.appfuse.dao.hibernate.GenericDaoHibernate;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.celtic.dao.ProjectUrlDao;
import com.celtic.model.ProjectUrl;

@Repository
public class ProjectUrlDaoHibernate extends GenericDaoHibernate<ProjectUrl,Long> implements ProjectUrlDao {
	
	public ProjectUrlDaoHibernate() {
		super(ProjectUrl.class);	
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<ProjectUrl> findByProjectInstance(Long id, String instanceName) {
		 log.fatal("Instance Name"+instanceName);
		 log.fatal("projectId"+id);
		 Criteria criteria=getSession().createCriteria(ProjectUrl.class);
		 criteria.add(Restrictions.eq("instanceName", instanceName));
		 criteria.add(Restrictions.eq("id", id));		
		 return (List<ProjectUrl>)criteria.list();
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<ProjectUrl> findByProject(Long projectId) {
		 Criteria criteria=getSession().createCriteria(ProjectUrl.class,"url");
		 criteria.createAlias("url.project", "project")
		 .add(Restrictions.eq("project.id",projectId));
		 return (List<ProjectUrl>)criteria.list();
		
	}
	
	
	

}
